<template>
	<view class="container bacFFF">
		<view class="wid100 coFFF" style="background: #3978F9;height: 400rpx;">
			<view style="height: 70rpx;"></view>
			<view class="textCen" style="font-size: 100rpx;display: flex;align-items: center;justify-content: center;"><text style="font-size: 40rpx;">我的积分：</text><text>{{toMoney.score}}</text></view>
			<view class="dis disAl disJuC foSi20">
				<i class="fa fa-exclamation-circle"></i>
				<view class="mar-left10" @click="godetails()">积分兑换规则</view>
			</view>
			<view style="height: 70rpx;"></view>
			<view class="dis disAl disJuC foSi25">
				<view class="hei60 dis disAl disJuC borRad40" @click.stop="tiaozhuan('/pages/user/pointsList')"
					style="width: 200rpx;border: 2rpx solid #ffffff;">积分记录</view>
				<view class="hei60 dis disAl disJuC borRad40" @click.stop="tiaozhuan('/pages/user/pointsExchange')"
					style="width: 200rpx;border: 2rpx solid #ffffff;margin-left: 40rpx;">兑换记录</view>
				<view class="hei60 dis disAl disJuC borRad40" @click.stop="duihuan()"
					style="width: 200rpx;border: 2rpx solid #ffffff;margin-left: 40rpx;">兑换余额</view>
			</view>
		</view>
		<scroll-view scroll-y="true" @scrolltolower="lower" 
			class="wid90 mar" style="height: calc(100vh - 400rpx);">
			<view style="height: 42rpx;"></view>
			<view class="wid100 dis disAl disJuB flwa" style="flex-direction: row;">
				<view class="wid49 borRad20 bacFFF mar-bott30 vie1" @click="tiaozhuan('/pages/user/commodity?id='+item.id)"
					v-for="(item,index) in goods" :key="index" style="width: 49%;">
					<image :src="item.cover_img" class="wid100" style="height: 256rpx;"></image>
					<view style="height: 10rpx;"></view>
					<view class="wid90 mar">
						<view class="wid100 foSi25 overflowHidden fowebl">{{item.title}}</view>
						<view class="wid100 dis disJuB mar-top10" style="align-items: flex-end;">
							<view class="foSi20" style="color: #FF0000;">{{item.price}}积分</view>
							<view class="dis disAl disJuC coFFF borRad40" @click.stop="tiaozhuan('/pages/user/exchange?id='+item.id)"
								style="width: 80rpx;height: 40rpx;background: #3978F9;">兑换</view>
						</view>
					</view>
					<view style="height: 30rpx;"></view>
				</view>
			</view>
			<view class="hei20"></view>
		</scroll-view>
	</view>
</template>

<script>
	import { Goods } from '../../model/integralgoods-model';
	var Goods2 = new Goods()
	export default {
		data() {
			return {
				last_page: 0,
				pge: 1,
				integral:0,
				goods:[],
				toMoney: {
					money: 0.00, //现有
					score: 0.00, //现有积分
					to_money: 0.00 //可兑换余额
				}
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad: function(e) {
			this.getdata()
			this.getList()
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {
			duihuan(){
				var that = this
				if(that.toMoney.score < 100){
					return uni.showToast({
						title:'最低100积分可兑换',
						icon:'none'
					})
				}
				var content = '是否使用积分兑换'+that.toMoney.to_money+'元？'
				uni.showModal({
						title: '提示',
						content: content,
						success: function(res) {
						if (res.confirm) {
						    // 执行确认后的操作
							let params = {
								money: that.toMoney.to_money
							}
							Goods2.toExchange((data) => {
								console.log(data)
								if (data.code === 0) {
									that.getList()
								} else {
									uni.showToast({
										title: data.msg,
										icon: 'none',
										duration: 2000
									})
								}
							}, params)
						}
					}
				})
			},
			getList(){
				var that = this
				let params = {}
				Goods2.toMoney((data) => {
					console.log(data)
					if (data.code === 0) {
						that.toMoney = data.data
					} else {
						uni.showToast({
							title: data.msg,
							icon: 'none',
							duration: 2000
						})
					}
				}, params)
			},
			getdata(){
				var that = this
				let params = {}
				Goods2.Lists((data) => {
					console.log(data)
					if (data.code === 0) {
						that.goods = data.data.goods
						that.integral = data.data.integral
						
					} else {
						uni.showToast({
							title: data.msg,
							icon: 'none',
							duration: 2000
						})
					}
				}, params)
			},
			godetails(){
				uni.navigateTo({
					url:'/pages/articledetail/index?id=66'
				})
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				});
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
				}
			},
		}
	};
</script>
<style>
	.container {
		height: 100vh;
	}
	.vie1{
		overflow: hidden;
		box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);
	}
</style>